package spring.boot.fastdep.jwt.service;

import com.louislivi.fastdep.shirojwt.jwt.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import spring.boot.fastdep.jwt.common.Results;
import spring.boot.fastdep.jwt.model.TUser;
import spring.boot.fastdep.jwt.utils.PasswordUtils;
import spring.boot.fastdep.jwt.utils.StringUtils;
import spring.boot.fastdep.jwt.vo.TUserRegVO;

@Service
public class RegService {

    @Autowired
    private JwtUtil jwtUtil;


    public Results regPhoneCode(TUserRegVO vo) {
        if (vo == null || StringUtils.isNull(vo.getPhone()) || StringUtils.isNull(vo.getCode())) {
            return Results.paramError("注册参数错误");
        }
        if ("18888888888".equals(vo.getPhone()) && "666666".equals(vo.getCode())) {
            TUser tUser = new TUser();
            tUser.setId(100L);
            tUser.setUsername(vo.getPhone());
            tUser.setPassword(PasswordUtils.md5Pass("123456"));
            Object token = jwtUtil.sign(String.valueOf(tUser.getId()));
            return Results.success(token);
        } else {
            return Results.paramError("注册参数错误");
        }
    }
}
